package org.itworks.biodev.gui;

import java.awt.event.*;
import java.sql.*;

import javax.swing.*;

import org.itworks.biodev.model.*;
import org.itworks.helpers.mvc.*;

public class EditParticipantToMeetingDialogControler extends AbstractControler {
	private EditParticipantToMeetingDialogModel model;
	
	public EditParticipantToMeetingDialogControler(EditParticipantToMeetingDialogModel model, Meeting m, Customer c) {
		this.model = model;
		this.model.setParticipant(c);
		this.model.setMeeting(m);
	}
	
	public EditParticipantToMeetingDialogModel getModel() {
		return this.model;
	}

	public void viewLoaded() {
		// TODO Auto-generated method stub
		try {
			this.getModel().setCustomersList( CustomerMeetingTable.getInstance().findAllOrderedByLastNameNotInMeeting(this.model.getMeeting()));
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void okButtonActionPerformed(ActionEvent actionEvent,
			int selectedIndex) {
		// TODO Auto-generated method stub
		if(selectedIndex > -1) {
			// TODO Auto-generated method stub
			try {
				// R�cup�rer le client s�lectionn�
				Customer c = this.getModel().getCustomers().elementAt(selectedIndex);
				boolean add = false;
				
				CustomerMeeting cm = new CustomerMeeting();
				cm.setCustomer(c);
				cm.setMeeting(model.getMeeting());
				
				CustomerMeetingTable.getInstance().add(cm);
				
				
				
			} catch(Exception e) {
				e.printStackTrace();
			}
		} else {
			JOptionPane.showMessageDialog(null, "Aucun client n'a �t� s�lectionn� !", "Erreur", JOptionPane.ERROR_MESSAGE);
		}
		
	}
}
